package page.Beans;

import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import basicTypes.RALog;
import basicTypes.RALogExt;
import basicTypes.RAResource;

public class recHist {
	private List<RALogExt> logs;
	
	public recHist(loginBean x) throws SQLException{
		logs = initializeLogs(x);
	}

	public void setLogs(List<RALogExt> logs) {
		this.logs = logs;
	}

	public List<RALogExt> getLogs() {
		return logs;
	}
	
	private List<RALogExt> initializeLogs(loginBean x) throws SQLException{
		List<RAResource> novo = x.getBd().db_getResource(x.getUser(), "");
		List<RALogExt> novo2 = new LinkedList<RALogExt>();
		
		for(int i = 0; i<novo.size(); i++){
			List<RALog> aux = x.getBd().db_historyResource(x.getUser(), novo.get(i).getId());
			for(int j = 0; j < aux.size(); j++){
				RALogExt novoAux = new RALogExt(aux.get(j).getID(),aux.get(j).getClientID(), aux.get(j).getResourceID(),aux.get(j).getOperation(), aux.get(j).getDescription(), aux.get(j).getDate());
				novo2.add(novoAux);
			}
		}
		
		return novo2;
		
	}
	
}
